import com.typesafe.config.ConfigFactory

import java.sql.{Connection, DriverManager}

object ScalaJdbc {
  def main(args: Array[String]): Unit = {
    val conn = getConnection;
//    val statement = conn.prepareStatement("insert into score_board values(?,?,?)")
//    statement.setInt(1,1);
//    statement.setString(2, "InsertUseJdbc");
//    statement.setInt(3, 99)
//    statement.execute()


    val statement = conn.prepareStatement("select * from dim.dim_xl_org limit 5")
    val rs = statement.executeQuery()
    while(rs.next()){
      print(rs.toString)
    }

  }



  def getConnection: Connection = {
//    val config = ConfigFactory.load()
//    val url = config.getString("db.default.url")
//    val user = config.getString("db.default.user")
//    val password = config.getString("db.default.password")
//    val driver = config.getString("db.default.driver")
//
//    Class.forName(driver)
//    val connection = DriverManager.getConnection(url, user, password)
    val config = ConfigFactory.load()
    val url = config.getString("db.postgresql.url")
    val user = config.getString("db.postgresql.user")
    val password = config.getString("db.postgresql.password")
    val driver = config.getString("db.postgresql.driver")

    Class.forName(driver)
    val connection = DriverManager.getConnection(url, user, password)
    connection
  }
}
